<template>
    <section>
        <el-col :span="24">
            <el-input v-model.trim="number" placeholder="请输入RFID" @keyup.enter.native="searchBtn" size="small" clearable style="width: 250px;margin-right: 4px;"></el-input>
            <el-button type="primary" class="el-icon-search" @click="searchBtn" size="small"
                       :loading="btnLoading">查询</el-button>
        </el-col>
        <el-col :span="24" style="margin-top: 20px; font-size: 16px;font-weight: 400">
            <el-row>
                <span v-if="data.factory_name">{{data.factory_name}}</span>
                <span v-if="data.sku_code">（{{data.sku_code}}）</span>
            </el-row>
            <el-row>
                <el-timeline style="margin-top: 40px">
                    <el-timeline-item v-for="(item, index) in lineList" :key="index" :timestamp="item.timestamp" :type="item.type">{{ item.content }}</el-timeline-item>
                </el-timeline>
            </el-row>
        </el-col>
    </section>
</template>

<script>

import {rfidSearch} from "@/api/produce/rfid";

export default {
    name: "produce_rfid_search",
    data() {
        return {
            tableHeight: window.innerHeight - 210,
            selectIndex: 0,
            btnLoading: false,
            loading: false,
            page: 1,
            limit: 20,
            total: 0,
            data: {},
            user: {},
            nodeActions: [],

            number: "",
            lineList: [],
        }
    },
    created() {
        this.user = this.$store.getters.user;
        this.nodeActions = this.user.node_actions[this.$route.meta.id] ? this.user.node_actions[this.$route.meta.id] : [];
    },
    methods: {
        //搜索按钮
        searchBtn() {
            this.data = {};
            this.lineList = [];
            this.btnLoading = true;
            rfidSearch({number: this.number}).then((res) =>{
                this.btnLoading = false;
                this.data = res.data;
                if(res.data.createtime){
                    this.lineList.push({content: '生成', timestamp: res.data.createtime, type: 'info'});
                }
                if(res.data.printing_time){
                    this.lineList.push({content: '打印', timestamp: res.data.printing_time, type: 'info'});
                }
                res.data.list.forEach(item =>{
                    let user = item.qt_user ? item.qt_user : item.qc_user;
                    let status = item.status ? "合格" : "不合格";
                    let reason_title = item.reason_title ? "："+item.reason_title : "";
                    let type = item.qt_user ? "仓检员" : "QC质检员";
                    this.lineList.push({
                        content: `${type}（${user}）：已检（${status}${reason_title}）`,
                        timestamp: item.qc_time,
                        type: 'primary'});
                });
                if(res.data.status == 4 && res.data.ware_time){
                    this.lineList.push({content: '入库', timestamp: res.data.ware_time, type: 'success'});
                }
            }).catch(()=>{
                this.btnLoading = false;
            })
        },

    },
    mounted() {

    }
}
</script>

<style scoped>

</style>
